﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mesuro.DataManagement {
	public class ExperimentHeader {
		internal Database Database { get; set; }
		internal int? ID { set; get; }//Nullable<int> allows the value to be null when no id has been set


		public string Description { get; set; }

		private string _short = null;
		public string ShortDescription {
			get { return _short ?? ((Description.Length > 50) ? Description.Substring( 47 ) + "..." : Description); }
			set { _short = value; }
		}

		public string Timestamp { set; get; }
		public double Frequency { set; get; }
		public int Harmonics { set; get; }
		public int Bias1 { set; get; }
		public int Bias2 { set; get; }
		public int DcMeasured { set; get; }
		internal string MetadataPath { get; set; }

		private Experiment _data = null;
		public Experiment Data {
			get {
				if (_data == null)
					_data = new Experiment( this );
				return _data;
			}
		}

		public void Save( Database database = null ) {
			if (database == null)
				database = Database;

			if (database == null)
				throw new InvalidOperationException( "Cannot save without a database reference" );

			database.Update( this );
		}

		//public string sourceFile { set; get; }
		//public string acquisation_software { set; get; }
		//public string operator_ { set; get; }
	}

}